package com.fanhao.dllo.justforyou.adapter;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.fanhao.dllo.justforyou.R;
import com.fanhao.dllo.justforyou.entity.NewPost;
import com.fanhao.dllo.justforyou.entity.NewsCommentNewPostsResult;
import com.fanhao.dllo.justforyou.view.MyImageView;
import com.fanhao.dllo.justforyou.volley.GetVolleyDatasUtil;

import java.util.List;

/**
 * Created by dllo on 15/11/6.
 */
public class NewsCommentNewViewAdapter extends BaseAdapter {
    private MyImageView imgIv;
    private TextView nameTv,timeTv,likeTv,contentTv;
    private List<NewPost> newPosts;


    public void addData(List<NewPost> datas){
        newPosts = datas;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return newPosts != null &&
                newPosts.size() > 0 ? newPosts.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {

        LayoutInflater inflater = LayoutInflater.from(parent.getContext());
        convertView = inflater.inflate(R.layout.activity_news_comment_item_hot,null );
        }

        imgIv = (MyImageView) convertView.findViewById(R.id.imgIv);
        nameTv = (TextView)convertView.findViewById(R.id.nameTv);
        timeTv = (TextView)convertView.findViewById(R.id.timeTv);
        likeTv = (TextView)convertView.findViewById(R.id.likeTv);
        contentTv = (TextView)convertView.findViewById(R.id.contentTv);

        if (newPosts != null) {
            NewPost newPost = newPosts.get(position);
            nameTv.setText(newPost.getF());

            timeTv.setText(newPost.getT());
            likeTv.setText(newPost.getV());
            contentTv.setText(newPost.getB());

            String imgUrl = newPost.getTimg();
            GetVolleyDatasUtil.getBitmapRequest(imgUrl, imgIv);

        }

        return convertView;
    }
}
